package com.cy.store.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect         //标记为切面类
@Component      //将当前类对象交给spring容器维护
public class TimerAspect {
    @Around("execution(* com.cy.store.service.impl.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();     //开始时间
        Object res = pjp.proceed();          //调用目标方法：业务层执行的方法
        long end = System.currentTimeMillis();       //结束时间
        System.out.println("耗时：" + (end-start));
        return res;
    }
}
